<% 
  	/**
	 * workoutsCreateWorkout.jsp
	 * 
	 * This is basically a blank page which is used to create a workout object
	 * and set it as a session variable for further modification. 
	 * The fifth page of a sequence of forms requisitioning the user for the information about their workout.
	 * The complete sequence is:
	 * workoutsCalendar.jsp -- Gets date
	 * workouts.jsp -- Gets information common between workout types: userID, prescribed, and type
	 * workoutsCreateWorkout.jsp -- redirect dummy page, creates the actual workout object and puts in the fields 
	 * 	we've already gotten from the user
	 * workoutsAMRAP.jsp/workoutsTimed.jsp/workoutsTabata.jsp -- Gets the type-specific workout information
	 * workoutsCreateWorkoutTyped.jsp -- redirect dummy page, adds the typed information to our Workout object
	 * workoutsAddExercise.jsp -- Allows the user to select individual exercises and append them to the list in our
			exercise.
	 * workoutsCreateExercise.jsp -- redirect dummy page, adds the exercise to our Workout object
	 * workoutsSubmit.jsp -- final page, submits the fully created workout to the database
	 * @author Chris
	 */
%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
   	pageEncoding="ISO-8859-1"%>
<%@page import="b1w1nn1ng.crossf1t.db.*"%>
<%@page import="b1w1nn1ng.crossf1t.gui.*"%>
<%@page import="b1w1nn1ng.crossf1t.business.*"%>
<%@page import="java.util.*" %>

<% 
	User user = (User) session.getAttribute("user");
	session.setAttribute("user", user);
	
	Workout wo = (Workout) session.getAttribute("curWorkout");
	String type = wo.getType();
	
	try {
	if(type.equals("amrap")) {
		((AMRAP)wo).setTimeLimit(Integer.parseInt(request.getParameter("time")));
		((AMRAP)wo).setRoundsCompleted(Integer.parseInt(request.getParameter("rounds")));
	} else if(type.equals("tabata")) {
		((Tabata)wo).setScore(Integer.parseInt(request.getParameter("score")));
	} else if(type.equals("timed")) {
		((Timed)wo).setTime(Integer.parseInt(request.getParameter("time")));
	} else {
		System.err.println("You broke workoutsCreateWorkoutTyped.jsp");
	}
	} catch(NumberFormatException e) {
		out.println("One of the data fields you entered had invalid input. Please try again.");
		out.println("<input type=\"button\" value=\"Start over\" onclick=\"window.location =\'workoutsCalendar.jsp\'\"/>");
		out.println("<input type=\"button\" value=\"Cancel\" onclick=\"window.location =\'home.jsp\'\"/>");
	}
	
	session.setAttribute("curWorkout", wo);
	response.sendRedirect("workoutsAddExercise.jsp");

%>
